package com.stateMode;

/**
 * 颁发礼物状态
 */
public class DispenseState extends State{

    RaffleActivity activity ;

    //构造
    public DispenseState(RaffleActivity activity) {
        this.activity = activity;
    }

    @Override
    public void deductMoney() {
        System.out.println("不用扣除积分 ");
    }

    @Override
    public boolean raffle() {
        System.out.println("此刻不可抽奖");
        return false;
    }

    @Override
    public void dispensePrise() {
        if (activity.getCount() > 0 ){
            //此刻奖品还有剩余
            System.out.println("恭喜你中奖了");
            int leftNum  = activity.getCount()-1;
            activity.setCount(leftNum-1);
            if (leftNum <= 0 ){
                //如果奖品没有了，直接进入奖品发送完毕状态 ， 活动结束
                System.out.println("奖品发完了");
                activity.setState(activity.getDispensOutState());
                return;
            }
            //状态变为不可抽奖
            activity.setState(activity.getNoRaffleState());
        }else {
            System.out.println("很遗憾奖品发完了 ... ");
            //更改状态为奖品发放完毕
            activity.setState(activity.getDispensOutState());
        }
    }
}
